<?php

namespace App;

use App\Replies as RepliesModel;

class Article extends Base
{
    protected $table = 'article';

    protected $fillable = ['title', 'category_id', 'is_recommend', 'content'];


    const IS_RECOMMEND = [
        0 => '不推荐',
        1 => '推荐',
    ];

    public function isRecommend()
    {
        return self::IS_RECOMMEND[$this->is_recommend];
    }

    public function category()
    {
        return $this->belongsTo('App\Category', 'category_id', 'id');
    }

    public function replies()
    {
        return $this->belongsTo('App\Replies', 'id', 'article_id');
    }

    public function repliesCount()
    {
        return RepliesModel::where('article_id', '=', $this->id)->count();
    }
}
